# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: nyanmisaka <nst799610810@gmail.com>

pkgname=jellyfin-ffmpeg
pkgver=6.0.6
pkgrel=2
pkgdesc='Jellyfin fork of ffmpeg'
arch=('loong64' 'x86_64')
url='https://github.com/jellyfin/jellyfin-ffmpeg'
license=('GPL3')
depends=(
  'glibc'
  'alsa-lib'
  'bzip2'
  'fontconfig'
  'fribidi'
  'gmp'
  'gnutls'
  'lame'
  'libass.so'
  'libbluray.so'
  'libchromaprint.so'
  'libdav1d.so'
  'libdrm'
  'libfreetype.so'
  'libopenmpt.so'
  'libplacebo.so'
  'libtheora'
  'libva.so'
  'libva-drm.so'
  'libvdpau'
  'libvorbisenc.so'
  'libvorbis.so'
  'libvpx.so'
  'libwebp'
  'libx11'
  'libx264.so'
  'libx265.so'
  'libxext'
  'libxml2'
  'libzimg.so'
  'ocl-icd'
  'onevpl'
  'opus'
  'shaderc'
  'srt'
  'vulkan-icd-loader'
  'xz'
  'zlib'
  'zvbi'
)
makedepends=(
  'git'
  'nasm'
  'clang'
  'ffnvcodec-headers'
  'amf-headers'
  'opencl-headers'
  'vulkan-headers'
)
optdepends=(
  'intel-media-driver: for Intel VAAPI support (Broadwell and newer)'
  'intel-media-sdk: for Intel Quick Sync Video'
  'onevpl-intel-gpu: for Intel Quick Sync Video (Alder Lake and newer)'
  'intel-compute-runtime: for Intel OpenCL runtime based tonemapping'
  'libva-intel-driver: for Intel legacy VAAPI support (Comet Lake and older)'
  'libva-mesa-driver: for AMD VAAPI support'
  'nvidia-utils: for Nvidia NVDEC/NVENC support'
  'opencl-amd: for AMD OpenCL runtime based Tonemapping'
  'vulkan-radeon: for AMD RADV Vulkan support'
  'vulkan-intel: for Intel ANV Vulkan support'
)
options=('!lto')
_commit='a2ed32cd633a2665c62be6389ffbd49c708d4864'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed -e 's/^v//' -e 's/-/./'
}

prepare() {
  cd "$pkgname"

  # apply jellyfin patches to ffmpeg
  for i in debian/patches/*.patch; do
    patch -p1 -i "$i"
  done
}

build() {
  cd "$pkgname"

  ./configure \
    --prefix="/usr/lib/jellyfin-ffmpeg" \
    --target-os=linux \
    --extra-version=Jellyfin \
    --disable-doc \
    --disable-ffplay \
    --disable-ptx-compression \
    --disable-shared \
    --disable-libxcb \
    --disable-sdl2 \
    --disable-xlib \
    --enable-gpl \
    --enable-version3 \
    --enable-static \
    --enable-gmp \
    --enable-gnutls \
    --enable-chromaprint \
    --enable-libfontconfig \
    --enable-libass \
    --enable-libbluray \
    --enable-libdrm \
    --enable-libfreetype \
    --enable-libfribidi \
    --enable-libmp3lame \
    --enable-libopus \
    --enable-libopenmpt \
    --enable-libtheora \
    --enable-libvorbis \
    --enable-libdav1d \
    --enable-libwebp \
    --enable-libvpx \
    --enable-libx264 \
    --enable-libx265 \
    --enable-libzvbi \
    --enable-libzimg \
    --enable-libshaderc \
    --enable-libplacebo \
    --enable-vulkan \
    --enable-opencl \
    --enable-vaapi \
    --enable-amf \
    --enable-libvpl \
    --enable-ffnvcodec \
    --enable-cuda \
    --enable-cuda-llvm \
    --enable-cuvid \
    --enable-nvdec \
    --enable-nvenc

  make
}

package() {
  cd "$pkgname"

  install -vDm755 -t "$pkgdir/usr/lib/$pkgname" ff{mpeg,probe}
}
